package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import com.hmall.search.service.impl.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全
     *
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        return searchService.getSuggestion(prefix);
    }

    /**
     * 聚合字段
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) {
        return searchService.getFilters(params);
    }

    /**
     * 基本搜索功能
     * @param params
     * @return
     */
    @PostMapping("/list")
    public  PageDTO<ItemDoc> list(@RequestBody RequestParams params) {
        return searchService.list(params);
    }

}
